PROGRAM_NAME='Melton Common Include'
(***********************************************************)
(***********************************************************)
(*  FILE_LAST_MODIFIED_ON: 04/05/2006  AT: 09:00:25        *)
(***********************************************************)
(* System Type : NetLinx                                   *)
(***********************************************************)
(* REV HISTORY:                                            *)
(***********************************************************)
(*
    $History: $
*)
(***********************************************************)
(*          DEVICE NUMBER DEFINITIONS GO BELOW             *)
(***********************************************************)
DEFINE_DEVICE

(***********************************************************)
(*               CONSTANT DEFINITIONS GO BELOW             *)
(***********************************************************)
DEFINE_CONSTANT
cnMaxDebugLen = 200
cnMaxRooms    = 6
cnMaxSources  = 10
cnMaxTPs      = 2
cnMaxDMSs     = 3
cnMaxUIs      = 6

cnPanelTypeTP  = 1
cnPanelTypePC  = 2
cnPanelTypeRTI = 3
cnPanelTypeKP  = 4

// AV Zone IDs
cnFamilyID       = 1
cnKitchenID      = 2
cnPatioID        = 3
cnGarageID       = 4
cnMBedID         = 5
cnMBathID        = 6

//UI IDs
cnIpadID         = 1
cnFamilyTPID     = 2
cnKitchenKPID    = 3
cnGarageKPID     = 4
cnMBedTPID       = 5
cnMBathKPID      = 6

cnMaxIpads = 1

// Source IDs
cnFamilyDtvID  = 1
cnFamilyDvdID  = 2
cnFamilyPs3ID  = 3
cnKitchenPCID  = 4
cnFamilyIpodID = 5
cnFamilyCdID   = 6
cnSatMusicID   = 7

cnMBedDTVID    = 8
cnMBedDVDID    = 9
cnMBedPS3ID    = 10

cnAS16_1_OutFamily  = 1
cnAS16_1_OutMBed    = 2
cnAS16_1_OutAngel   = 3
cnAS16_1_OutPatio   = 4
cnAS16_1_OutMBath   = 5
cnAS16_1_OutKitchen = 6
cnAS16_1_OutGarage  = 7

cnOffConfirmation = 31
cn3dAddress = 44

cnRoomVolumeLevelChan = 1
cnRoomVolumeInLevelChan = 2
cnRoomSourceValueLevelChan = 3

(***********************************************************)
(*              DATA TYPE DEFINITIONS GO BELOW             *)
(***********************************************************)
DEFINE_TYPE


Structure _sRoomInfo
{
	Char    strName[25]
	Integer nID
	Integer nAudioOutput
	Integer nVideoOutput
	Integer nHDOutput
	Integer nCurrentSource
}

Structure _sSourceInfo
{
	Integer nSourceValue
	Integer nIsGlobalSource
	Integer nAudioInput
	Integer nVideoInput
	Integer nHDInput
	Char    strName[25]	
	Integer nInUse
}

Structure _sUI
{
    Integer nZone
    Integer nPage
    Integer nZoneListLen
    Integer nZoneListPos
    Integer nAwake
    Integer nClimateActive
    Integer nGlobalActive
}

Structure _sDMS
{
  Char    strFileName[80]
  Char    anVarText[200][20]
  Integer nLevel[33]
}

STRUCTURE _sAudioSwitcher
{
  CHAR          strBuff[100]
  CHAR          strData[50]
  FLOAT         nLevel[33]
  INTEGER       nOutputStatus[16]
  INTEGER       nLowVol[16]
  INTEGER       nHighVol[16]
  INTEGER       nInput
  INTEGER       nOutput
}

(***********************************************************)
(*               VARIABLE DEFINITIONS GO BELOW             *)
(***********************************************************)
DEFINE_VARIABLE
Volatile _sRoomInfo sRoomInfo[cnMaxRooms]
Volatile _sSourceInfo sSourceInfo[cnMaxSources]
Volatile _sUI sUI[cnMaxUIs]

// Time settings
Volatile Char dTmTzName[] = 'Mountain' // time zone name
Volatile Char dTmTzDesc[] = 'M%sT' // time zone description
Volatile Double dTmTzGmtOffset = -7.0 // gmt offset
Volatile Char strTmTzDstRules[] = 'US' // Daylight rule set
(* Location *)
Volatile Char strTmLocName[] = 'Aspen' // local name
Volatile Double dTmLocLat = 39.7 // local lat for GJ
Volatile Double dTmLocLong = 108.32 // local long for GJ
(* Timeserver *)
Volatile Integer nTmTsProtocol = 3 // sntp protocol
Volatile Integer nTmTsCheckTime = 0 // Check Time interval in seconds.  Use 0 for default (2 hours).  ex: 3600
Volatile Char strTmTsServer[] = 'tick.usno.navy.mil'

Volatile Integer nRoomButtons[] = 
{
    30,  // 1- Off
    41,  // 2- Source1 Local DTV
    42,  // 3- Source2 Local DVD
    43,  // 4- Source3 Local PS3
    44,  // 5- Source4 Kitchen PC
    45,  // 6- Source5 iPod
    46,  // 7- Source6 Family CD
    47,  // 8- Source7 Family Sat Music
    999,  // 9- Source8 
    999,  // 10- Source9
    999,  // 11- Source10
    999,  // 12- Source11
    999,  // 13- Source12
    999,  // 14- Source13
    999,  // 15- Source14
    999,  // 16- Source15
    999,  // 17- Source16
    999,  // 18- Source17
    999,  // 19- Source18
    999,  // 20- Source19
    999,  // 21- Source20
    961,  // 22- Vol Up
    962,  // 23- Vol Down
    963   // 24- Mute Toggle
}

Volatile Integer nRoomTextChans[] = {102,109,18} // Source Text, Room Name, Volume
Volatile Integer nRoomLevelChans[] = {1,2} // Voume, Source Value

Volatile Integer nGlobalGroupSelectButtons[] = {901,902,903,904,905,906,907,908,909,910}
Volatile Integer nGlobalZoneSelectButtons[] = {1961,1962,1963,1964,1965,1966,1967,1968,1969,1970}
Volatile Integer nGlobalSourceSelectButtons[] = {920,921,922,923,924,925,926,927,928,929,930}
Volatile Integer nClearZoneSelectButton = 1954
Volatile Integer nGlobalScrollUpButton = 1950
Volatile Integer nGlobalScrollDownButton = 1951
Volatile Integer nGlobalVolumeUpButton = 1941
Volatile Integer nGlobalVolumeDownButton = 1942
Volatile Integer nGlobalSourceControlButton = 1952
Volatile Integer nGlobalDisableConnectChan = 1953
Volatile Integer nGlobalRoomTextChans[] = {281,282,283,284,285,286,287,288,289,290}
Volatile Integer nGlobalSourceTextChans[] = {291,292,293,294,295,296,297,298,299,300}
Volatile Integer nGlobalVolumeTextChans[] = {271,272,273,274,275,276,277,278,279,280}
Volatile Integer nGlobalSourceSelection

Volatile Integer nGlobalSelectedZoneOffButton = 920
Volatile Integer nGlobalListPort = 1
Volatile Integer nGlobalListAddress = 2
Volatile Integer nGlobalListViewAddress = 2

Volatile Integer nZoneListSelectButtons[] = {1801,1802,1803,1804,1805,1806,1807,1808,1809,1810}
Volatile Integer nZoneListRoomTextChans[] = {301,302,303,304,305,306,307,308,309,310}
Volatile Integer nZoneListScrollUpButton = 1850
Volatile Integer nZoneListScrollDownButton = 1851
Volatile Integer nZoneListScrollTopButton = 1852

Volatile Integer nZoneListPort = 1
Volatile Integer nZoneListAddress = 1
Volatile Integer nZoneListViewAddress = 1

Volatile Dev daAllUIs[]=
{
    dvIpad,
    dvFamilyTP,
    dvMBedTP,
    vdvKitchenKP,
    vdvGarageKP,
    vdvMBathKP
}

Volatile Dev daAllIpads[] = {dvIpad}

Volatile Integer nSatButtons[] =
{
    215, // 1- Play
    216, // 2- Stop
    217, // 3- Pause
    218, // 4- ScanFwd
    219, // 5- ScanRev
    222, // 6- Record
    999, // 7- Power
    200, // 8- 0
    201, // 9- 1
    202, // 10- 2
    203, // 11- 3
    204, // 12- 4
    205, // 13- 5
    206, // 14- 6
    207, // 15- 7
    208, // 16- 8
    209, // 17- 9
    211, // 18- Dash
    213, // 19- Enter
    228, // 20- ChanUp
    229, // 21- ChanDn
    237, // 22- Jump
    243, // 23- Back
    251, // 24- Up
    252, // 25- Dow
    253, // 26- Left
    254, // 27- Right
    255, // 28- Select
    262, // 29- Clear
    261, // 30- Guide
    223, // 31- Replay
    238, // 32- Red
    239, // 33- Green
    240, // 34- Yellow
    241, // 35- Blue
    227, // 36- Advance
    260, // 37- Menu
    269, // 38- List
    265, // 39- Display
    172, // 40- Active
    999  // 41- Format
}

Volatile Integer nSatPresetButtons[] =
{
    421, // 1- Preset1
    422, // 2- Preset2
    423, // 3- Preset3
    424, // 4- Preset4
    425, // 5- Preset5
    426, // 6- Preset6
    427, // 7- Preset7
    428, // 8- Preset8
    429, // 9- Preset9
    430, // 10- Preset10
    431, // 11- Preset11
    432, // 12- Preset12
    433, // 13- Preset13
    434, // 14- Preset14
    435, // 15- Preset15
    436, // 16- Preset16
    437, // 17- Preset17
    438, // 18- Preset18
    439, // 19- Preset19
    440, // 20- Preset20
    441, // 21- Preset21
    442, // 22- Preset22
    443, // 23- Preset23
    444, // 24- Preset24
    445, // 25- Preset25
    446, // 26- Preset26
    447, // 27- Preset27
    448, // 28- Preset28
    449, // 29- Preset29
    450, // 30- Preset30
    451, // 31- Preset31
    452, // 32- Preset32
    453, // 33- Preset33
    454, // 34- Preset34
    455, // 35- Preset35
    456, // 36- Preset36
    457, // 37- Preset37
    458, // 38- Preset38
    459, // 39- Preset39
    460, // 40- Preset40
    461, // 41- Preset41
    462, // 42- Preset42
    463, // 43- Preset43
    464, // 44- Preset44
    465, // 45- Preset45
    466, // 46- Preset46
    467, // 47- Preset47
    468, // 48- Preset48
    469, // 49- Preset49
    470  // 50- Preset50
}

Volatile Integer nSatPresetBmpChans[] =
{
    421, // 1- Preset1
    422, // 2- Preset2
    423, // 3- Preset3
    424, // 4- Preset4
    425, // 5- Preset5
    426, // 6- Preset6
    427, // 7- Preset7
    428, // 8- Preset8
    429, // 9- Preset9
    430, // 10- Preset10
    431, // 11- Preset11
    432, // 12- Preset12
    433, // 13- Preset13
    434, // 14- Preset14
    435, // 15- Preset15
    436, // 16- Preset16
    437, // 17- Preset17
    438, // 18- Preset18
    439, // 19- Preset19
    440, // 20- Preset20
    441, // 21- Preset21
    442, // 22- Preset22
    443, // 23- Preset23
    444, // 24- Preset24
    445, // 25- Preset25
    446, // 26- Preset26
    447, // 27- Preset27
    448, // 28- Preset28
    449, // 29- Preset29
    450, // 30- Preset30
    451, // 31- Preset31
    452, // 32- Preset32
    453, // 33- Preset33
    454, // 34- Preset34
    455, // 35- Preset35
    456, // 36- Preset36
    457, // 37- Preset37
    458, // 38- Preset38
    459, // 39- Preset39
    460, // 40- Preset40
    461, // 41- Preset41
    462, // 42- Preset42
    463, // 43- Preset43
    464, // 44- Preset44
    465, // 45- Preset45
    466, // 46- Preset46
    467, // 47- Preset47
    468, // 48- Preset48
    469, // 49- Preset49
    470  // 50- Preset50
}

Volatile Integer nSatPresetTextChans[] =
{
    471, // 1- Preset1
    472, // 2- Preset2
    473, // 3- Preset3
    474, // 4- Preset4
    475, // 5- Preset5
    476, // 6- Preset6
    477, // 7- Preset7
    478, // 8- Preset8
    479, // 9- Preset9
    480, // 10- Preset10
    481, // 11- Preset11
    482, // 12- Preset12
    483, // 13- Preset13
    484, // 14- Preset14
    485, // 15- Preset15
    486, // 16- Preset16
    487, // 17- Preset17
    488, // 18- Preset18
    489, // 19- Preset19
    490, // 20- Preset20
    491, // 21- Preset21
    492, // 22- Preset22
    493, // 23- Preset23
    494, // 24- Preset24
    495, // 25- Preset25
    496, // 26- Preset26
    497, // 27- Preset27
    498, // 28- Preset28
    499, // 29- Preset29
    500, // 30- Preset30
    501, // 31- Preset31
    502, // 32- Preset32
    503, // 33- Preset33
    504, // 34- Preset34
    505, // 35- Preset35
    506, // 36- Preset36
    507, // 37- Preset37
    508, // 38- Preset38
    509, // 39- Preset39
    510, // 40- Preset40
    511, // 41- Preset41
    512, // 42- Preset42
    513, // 43- Preset43
    514, // 44- Preset44
    515, // 45- Preset45
    516, // 46- Preset46
    517, // 47- Preset47
    518, // 48- Preset48
    519, // 49- Preset49
    520  // 50- Preset50
}   

Volatile Integer nSatCurrentInfoChans[1] = {114}

Volatile Integer nMasterSat = 1
Volatile Integer nSlaveSat = 0

Volatile Integer nSatMusicPresetButtons[] =
{
    521, // 1- Preset1
    522, // 2- Preset2
    523, // 3- Preset3
    524, // 4- Preset4
    525, // 5- Preset5
    526, // 6- Preset6
    527, // 7- Preset7
    528, // 8- Preset8
    529, // 9- Preset9
    530, // 10- Preset10
    531, // 11- Preset11
    532, // 12- Preset12
    533, // 13- Preset13
    534, // 14- Preset14
    535, // 15- Preset15
    536, // 16- Preset16
    537, // 17- Preset17
    538, // 18- Preset18
    539, // 19- Preset19
    540 // 20- Preset20
}

Volatile Integer nSatMusicPresetTextChans[] =
{
    201, // 1- Preset1
    202, // 2- Preset2
    203, // 3- Preset3
    204, // 4- Preset4
    205, // 5- Preset5
    206, // 6- Preset6
    207, // 7- Preset7
    208, // 8- Preset8
    209, // 9- Preset9
    210, // 10- Preset10
    211, // 11- Preset11
    212, // 12- Preset12
    213, // 13- Preset13
    214, // 14- Preset14
    215, // 15- Preset15
    216, // 16- Preset16
    217, // 17- Preset17
    218, // 18- Preset18
    219, // 19- Preset19
    220  // 20- Preset20
}

(***********************************************************)
(*               LATCHING DEFINITIONS GO BELOW             *)
(***********************************************************)
DEFINE_LATCHING

(***********************************************************)
(*       MUTUALLY EXCLUSIVE DEFINITIONS GO BELOW           *)
(***********************************************************)
DEFINE_MUTUALLY_EXCLUSIVE

(***********************************************************)
(*        SUBROUTINE/FUNCTION DEFINITIONS GO BELOW         *)
(***********************************************************)
(* EXAMPLE: DEFINE_FUNCTION <RETURN_TYPE> <NAME> (<PARAMETERS>) *)
(* EXAMPLE: DEFINE_CALL '<NAME>' (<PARAMETERS>) *)
Define_Call 'DEBUG_OUTPUT' (Integer nLine, Char strData[])
{
    #IF_DEFINED DEBUG
    Char strTempData[200];
    Integer nLen, nCurrentPos;
	
    nLen = Length_String(strData)
    If (nLen < cnMaxDebugLen)
    {
	Send_String 0,"__FILE__,' Line:',Itoa(nLine),' ',strData";
    }
    Else
    {
	strTempData = Left_String(strData,cnMaxDebugLen);
	Send_String 0,"__FILE__,' Line:',Itoa(nLine),' ',strTempData";
	nCurrentPos = cnMaxDebugLen
	While (nLen > nCurrentPos)
	{
	    strTempData = Mid_String(strData,nCurrentPos,cnMaxDebugLen);
	    nCurrentPos = nCurrentPos + cnMaxDebugLen
	    Send_String 0,"'Continued: ',strTempData";
	}
    }
    #END_IF
}

Define_Function Char[100] GET_IP_ERROR (LONG lERR)
{
    SELECT
    {
	ACTIVE (lERR = 0):
	    RETURN "";
	ACTIVE (lERR = 2):
	    RETURN "'IP ERROR (',ITOA(lERR),'): General Failure (IP_CLIENT_OPEN/IP_SERVER_OPEN)'";
	ACTIVE (lERR = 4):
	    RETURN "'IP ERROR (',ITOA(lERR),'): unknown host (IP_CLIENT_OPEN)'";
	ACTIVE (lERR = 6):
	    RETURN "'IP ERROR (',ITOA(lERR),'): connection refused (IP_CLIENT_OPEN)'";
	ACTIVE (lERR = 7):
	    RETURN "'IP ERROR (',ITOA(lERR),'): connection timed out (IP_CLIENT_OPEN)'";
	ACTIVE (lERR = 8):
	    RETURN "'IP ERROR (',ITOA(lERR),'): unknown connection error (IP_CLIENT_OPEN)'";
	ACTIVE (lERR = 14):
	    RETURN "'IP ERROR (',ITOA(lERR),'): local port already used (IP_CLIENT_OPEN/IP_SERVER_OPEN)'";
	ACTIVE (lERR = 16):
	    RETURN "'IP ERROR (',ITOA(lERR),'): too many open sockets (IP_CLIENT_OPEN/IP_SERVER_OPEN)'";
	ACTIVE (lERR = 10):
	    RETURN "'IP ERROR (',ITOA(lERR),'): Binding error (IP_SERVER_OPEN)'";
	ACTIVE (lERR = 11):
	    RETURN "'IP ERROR (',ITOA(lERR),'): Listening error (IP_SERVER_OPEN)'";
	ACTIVE (lERR = 15):
	    RETURN "'IP ERROR (',ITOA(lERR),'): UDP socket already listening (IP_SERVER_OPEN)'";
	ACTIVE (lERR = 9):
	    RETURN "'IP ERROR (',ITOA(lERR),'): Already closed (IP_CLIENT_CLOSE/IP_SERVER_CLOSE)'";
	ACTIVE (1):
	    RETURN "'IP ERROR (',ITOA(lERR),'): Unknown'";
    }
}

Define_Call 'PULSE_IR' (DEV dvDEV, INTEGER nCHAN)
{
  Send_Command dvDev,"'SP',nChan"
}

Define_Call 'SETUP_SOURCES_AUDIO' (Dev vdvRoom)
{
	// Format: SOURCE1=nSourceValue, nGlobalSource, nAudioInput, nVideoInput, nComponentInput, nAVRInput, nTVInput
	// nSourceValue: Unique source identifier
	// nGlobalSource: 0 = false, 1 = true
	// nAudioInput: Input used on the audio switcher this zone is connected to
	// nVideoInput: Input used on the video switcher this zone is connected to
	// nComponentInput: Input used on the HD switcher this zone is connected to
	// nAVRInput: Channel used to turn on AVR and select the correct input in its module
	// nTVInput: Channel used to turn on TV and select the correct input in its module
	// strName: Friendly name
	
	Send_Command vdvRoom,"'SOURCE5=',Itoa(sSourceInfo[cnFamilyIpodID].nSourceValue),',',Itoa(sSourceInfo[cnFamilyIpodID].nAudioInput),',',Itoa(sSourceInfo[cnFamilyIpodID].nVideoInput),',',Itoa(sSourceInfo[cnFamilyIpodID].nHDInput),',0,0,',sSourceInfo[cnFamilyIpodID].strName"
	Send_Command vdvRoom,"'SOURCE6=',Itoa(sSourceInfo[cnFamilyCdID].nSourceValue),',',Itoa(sSourceInfo[cnFamilyCdID].nAudioInput),',',Itoa(sSourceInfo[cnFamilyCdID].nVideoInput),',',Itoa(sSourceInfo[cnFamilyCdID].nHDInput),',0,0,',sSourceInfo[cnFamilyCdID].strName"
	Send_Command vdvRoom,"'SOURCE7=',Itoa(sSourceInfo[cnSatMusicID].nSourceValue),',',Itoa(sSourceInfo[cnSatMusicID].nAudioInput),',',Itoa(sSourceInfo[cnSatMusicID].nVideoInput),',',Itoa(sSourceInfo[cnSatMusicID].nHDInput),',0,0,',sSourceInfo[cnSatMusicID].strName"
}

Define_Call 'ADD_PANEL_TO_ZONE' (Dev dvPanel, Dev daZone[])
{
    If (Length_Array(daZone) < Max_Length_Array(daZone))
    {
	Set_Length_Array(daZone,Length_Array(daZone)+1)
	daZone[Length_Array(daZone)] = dvPanel
	Call 'DEBUG_OUTPUT' (__LINE__,"'ADD_PANEL_TO_ZONE New Length_Array(daZone)',Itoa(Length_Array(daZone))")
    }
}

Define_Call 'REMOVE_PANEL_FROM_ZONE' (Dev dvPanel, Dev daZone[])
{
    Stack_Var Integer nI
    Call 'DEBUG_OUTPUT' (__LINE__,"'REMOVE_PANEL_FROM_ZONE dvPanel:',Itoa(dvPanel.Number),':',Itoa(dvPanel.Port),',',Itoa(dvPanel.System),' Length_Array(daZone)',Itoa(Length_Array(daZone))")
    If (Length_Array(daZone) > 0)
    {
	For (nI = 1; nI <= Length_Array(daZone) -1; nI++)
	{
	    If (daZone[nI] == dvPanel)
	    {
		daZone[nI] = daZone[nI+1]
		daZone[nI+1] = dvPanel
		Call 'DEBUG_OUTPUT' (__LINE__,"'REMOVE_PANEL_FROM_ZONE Moving Panel[',Itoa(nI),']:',Itoa(daZone[nI].Number),':',Itoa(daZone[nI].Port),',',Itoa(daZone[nI].System),' Length_Array(daZone)',Itoa(Length_Array(daZone))")
	    }
	}
	Set_Length_Array(daZone,Length_Array(daZone)-1)
	Call 'DEBUG_OUTPUT' (__LINE__,"'REMOVE_PANEL_FROM_ZONE New Length_Array(daZone):',Itoa(Length_Array(daZone))")
    }
    Else
    {
	Call 'DEBUG_OUTPUT' (__LINE__,"'!!!!REMOVE_PANEL_FROM_ZONE ERROR.  Length Array daZone not greater than 0!!!!'")
    }
}

Define_Call 'ADD_PANEL_TO_SOURCE' (Dev dvPanel, Dev daSource[])
{
    Call 'DEBUG_OUTPUT' (__LINE__,"'ADD_PANEL_TO_SOURCE dvPanel:',Itoa(dvPanel.Number),':',Itoa(dvPanel.Port),':',Itoa(dvPanel.System),' Length_Array(daSource):',Itoa(Length_Array(daSource))")
    If (Length_Array(daSource) < Max_Length_Array(daSource))
    {
	Set_Length_Array(daSource,Length_Array(daSource)+1)
	daSource[Length_Array(daSource)] = dvPanel
	Call 'DEBUG_OUTPUT' (__LINE__,"'ADD_PANEL_TO_SOURCE New Length_Array(daSource)',Itoa(Length_Array(daSource))")
    }
}

Define_Call 'REMOVE_PANEL_FROM_SOURCE' (Dev dvPanel, Dev daSource[])
{
    Stack_Var Integer nI
    Call 'DEBUG_OUTPUT' (__LINE__,"'REMOVE_PANEL_FROM_SOURCE dvPanel:',Itoa(dvPanel.Number),':',Itoa(dvPanel.Port),':',Itoa(dvPanel.System),' Length_Array(daSource):',Itoa(Length_Array(daSource))")
    If (Length_Array(daSource) > 0)
    {
	For (nI = 1; nI <= Length_Array(daSource) -1; nI++)
	{
	    If (daSource[nI] == dvPanel)
	    {
		daSource[nI] = daSource[nI+1]
		daSource[nI+1] = dvPanel
		Call 'DEBUG_OUTPUT' (__LINE__,"'REMOVE_PANEL_FROM_SOURCE Moving Panel[',Itoa(nI),']:',Itoa(daSource[nI].Number),':',Itoa(daSource[nI].Port),',',Itoa(daSource[nI].System),' Length_Array(daSource)',Itoa(Length_Array(daSource))")
	    }
	}
	daSource[Length_Array(daSource)] = 0:0:0
	Set_Length_Array(daSource,Length_Array(daSource)-1)
	Call 'DEBUG_OUTPUT' (__LINE__,"'REMOVE_PANEL_FROM_SOURCE New Length_Array(daSource):',Itoa(Length_Array(daSource))")
	Return
    }
    Else
    {
	Call 'DEBUG_OUTPUT' (__LINE__,"'!!!!REMOVE_PANEL_FROM_SOURCE ERROR.  Length Array daSource not greater than 0!!!!'")
    }
}

(***********************************************************)
(*                STARTUP CODE GOES BELOW                  *)
(***********************************************************)
DEFINE_START

// Room Setup
sRoomInfo[cnFamilyID].strName = 'Family'
sRoomInfo[cnFamilyID].nID = cnFamilyID
sRoomInfo[cnFamilyID].nAudioOutput = cnAS16_1_OutFamily
sRoomInfo[cnFamilyID].nVideoOutput = 0
sRoomInfo[cnFamilyID].nHDOutput = 0

sRoomInfo[cnKitchenID].strName = 'Kitchen'
sRoomInfo[cnKitchenID].nID = cnKitchenID
sRoomInfo[cnKitchenID].nAudioOutput = cnAS16_1_OutKitchen
sRoomInfo[cnKitchenID].nVideoOutput = 0
sRoomInfo[cnKitchenID].nHDOutput = 0

sRoomInfo[cnPatioID].strName = 'Patio'
sRoomInfo[cnPatioID].nID = cnPatioID
sRoomInfo[cnPatioID].nAudioOutput = cnAS16_1_OutPatio
sRoomInfo[cnPatioID].nVideoOutput = 0
sRoomInfo[cnPatioID].nHDOutput = 0

sRoomInfo[cnGarageID].strName = 'Garage'
sRoomInfo[cnGarageID].nID = cnGarageID
sRoomInfo[cnGarageID].nAudioOutput = cnAS16_1_OutGarage
sRoomInfo[cnGarageID].nVideoOutput = 0
sRoomInfo[cnGarageID].nHDOutput = 0

sRoomInfo[cnMBedID].strName = 'Master Bed'
sRoomInfo[cnMBedID].nID = cnMBedID
sRoomInfo[cnMBedID].nAudioOutput = cnAS16_1_OutMBed
sRoomInfo[cnMBedID].nVideoOutput = 0
sRoomInfo[cnMBedID].nHDOutput = 0

sRoomInfo[cnMBathID].strName = 'Master Bath'
sRoomInfo[cnMBathID].nID = cnMBathID
sRoomInfo[cnMBathID].nAudioOutput = cnAS16_1_OutMBath
sRoomInfo[cnMBathID].nVideoOutput = 0
sRoomInfo[cnMBathID].nHDOutput = 0

// Source Setup
sSourceInfo[cnFamilyDtvID].nSourceValue = cnFamilyDtvID
sSourceInfo[cnFamilyDtvID].nIsGlobalSource = 0
sSourceInfo[cnFamilyDtvID].nAudioInput = 0
sSourceInfo[cnFamilyDtvID].nVideoInput = 0
sSourceInfo[cnFamilyDtvID].nHDInput = 1
sSourceInfo[cnFamilyDtvID].strName = 'Family DirecTv'

sSourceInfo[cnFamilyDvdID].nSourceValue = cnFamilyDvdID
sSourceInfo[cnFamilyDvdID].nIsGlobalSource = 0
sSourceInfo[cnFamilyDvdID].nAudioInput = 0
sSourceInfo[cnFamilyDvdID].nVideoInput = 0
sSourceInfo[cnFamilyDvdID].nHDInput = 1
sSourceInfo[cnFamilyDvdID].strName = 'HD DVD'

sSourceInfo[cnFamilyPs3ID].nSourceValue = cnFamilyPs3ID
sSourceInfo[cnFamilyPs3ID].nIsGlobalSource = 0
sSourceInfo[cnFamilyPs3ID].nAudioInput = 0
sSourceInfo[cnFamilyPs3ID].nVideoInput = 0
sSourceInfo[cnFamilyPs3ID].nHDInput = 0
sSourceInfo[cnFamilyPs3ID].strName = 'Family PS3'

sSourceInfo[cnKitchenPCID].nSourceValue = cnKitchenPCID
sSourceInfo[cnKitchenPCID].nIsGlobalSource = 0
sSourceInfo[cnKitchenPCID].nAudioInput = 0
sSourceInfo[cnKitchenPCID].nVideoInput = 0
sSourceInfo[cnKitchenPCID].nHDInput = 0
sSourceInfo[cnKitchenPCID].strName = 'Kitchen PC'

sSourceInfo[cnFamilyIpodID].nSourceValue = cnFamilyIpodID
sSourceInfo[cnFamilyIpodID].nIsGlobalSource = 1
sSourceInfo[cnFamilyIpodID].nAudioInput = 14
sSourceInfo[cnFamilyIpodID].nVideoInput = 0
sSourceInfo[cnFamilyIpodID].nHDInput = 0
sSourceInfo[cnFamilyIpodID].strName = 'Family iPod'

sSourceInfo[cnFamilyCdID].nSourceValue = cnFamilyCdID
sSourceInfo[cnFamilyCdID].nIsGlobalSource = 1
sSourceInfo[cnFamilyCdID].nAudioInput = 1
sSourceInfo[cnFamilyCdID].nVideoInput = 0
sSourceInfo[cnFamilyCdID].nHDInput = 0
sSourceInfo[cnFamilyCdID].strName = 'Family CD'

sSourceInfo[cnSatMusicID].nSourceValue = cnSatMusicID
sSourceInfo[cnSatMusicID].nIsGlobalSource = 1
sSourceInfo[cnSatMusicID].nAudioInput = 2
sSourceInfo[cnSatMusicID].nVideoInput = 0
sSourceInfo[cnSatMusicID].nHDInput = 0
sSourceInfo[cnSatMusicID].strName = 'Family Sat Music'

sSourceInfo[cnMBedDtvID].nSourceValue = cnMBedDtvID
sSourceInfo[cnMBedDtvID].nAudioInput = 0
sSourceInfo[cnMBedDtvID].nVideoInput = 0
sSourceInfo[cnMBedDtvID].nHDInput = 0
sSourceInfo[cnMBedDtvID].strName = 'Master Bed DirecTv'

sSourceInfo[cnMBedDvdID].nSourceValue = cnMBedDvdID
sSourceInfo[cnMBedDvdID].nAudioInput = 0
sSourceInfo[cnMBedDvdID].nVideoInput = 0
sSourceInfo[cnMBedDvdID].nHDInput = 0
sSourceInfo[cnMBedDvdID].strName = 'Master Bed Dvd'

sSourceInfo[cnMBedPS3ID].nSourceValue = cnMBedPS3ID
sSourceInfo[cnMBedPS3ID].nAudioInput = 0
sSourceInfo[cnMBedPS3ID].nVideoInput = 0
sSourceInfo[cnMBedPS3ID].nHDInput = 0
sSourceInfo[cnMBedPS3ID].strName = 'Master Bed PS3'

(***********************************************************)
(*            MODULE DEFINITIONS GO BELOW                  *)
(***********************************************************)

(***********************************************************)
(*                THE EVENTS GO BELOW                      *)
(***********************************************************)
DEFINE_EVENT

(***********************************************************)
(*            THE ACTUAL PROGRAM GOES BELOW                *)
(***********************************************************)
DEFINE_PROGRAM

(***********************************************************)
(*                     END OF PROGRAM                      *)
(*        DO NOT PUT ANY CODE BELOW THIS COMMENT           *)
(***********************************************************)

